<?php

//
// +---------------------------------------------------------+
// | 开发组
// +---------------------------------------------------------+
// | Copyrigh  (c)  2020 The PHP Group
// +---------------------------------------------------------+
// | 广告分类
// +---------------------------------------------------------+
// | zxc
// | php后端开发
// |
// +———————————————————+
//

namespace App\Models\Admin;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\DB;

class AdCate extends Model
{

    protected $table = 'ad_cate';
    protected $primaryKey = 'id';
    protected $dateFormat = 'U'; // 时间戳
    protected $casts = [
        'created_at' => 'datetime:Y-m-d H:i:s',
        'updated_at' => 'datetime:Y-m-d H:i:s'
    ];

    /**
     * 获取列表
     * @param type $where
     * @param type $page
     * @param type $limit
     */
    public static function getList($where = [], $limit = 20)
    {
        $list = self::where([])->orderBy('id', 'desc')->paginate($limit);
        return $list;
    }

    /**
     * 获取单条信息
     * @param type $id
     */
    public static function getInfoById($id)
    {
        return self::where(['id' => $id])->first();
    }

    /**
     * 添加信息
     * @param type $dataArr
     */
    public static function addInfo($dataArr)
    {
        $dataArr['created_at'] = time();
        $result = self::insert($dataArr);
        return $result;
    }

    /**
     * 更新信息
     * @param type $id
     * @param type $dataArr
     */
    public static function updateInfoById($id, $dataArr)
    {
        $result = self::where(['id' => $id])->update($dataArr);
        return $result;
    }

    /**
     * 删除数据
     * @param type $id
     */
    public static function deleteById($id)
    {
        $result = self::where(['id' => $id])->delete();
        return $result;
    }
}